package com.example.android.activity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.widget.Button;
import android.widget.ImageView;

import androidx.appcompat.app.AppCompatActivity;

import com.bumptech.glide.Glide;
import com.example.android.R;

public class SplashActivity extends AppCompatActivity {

    private Boolean isSkip = false;
    private Boolean isBack = false;

    private void skip() {
        isSkip = true;
        Intent intent = new Intent(SplashActivity.this, MainActivity.class);
        startActivity(intent);
        finish();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        Button button = findViewById(R.id.button);
        ImageView imageView = findViewById(R.id.imageView);

        Glide.with(this).load("http://81.68.141.72:8888/down/6Rw5PMoyQseB").into(imageView);

        button.setOnClickListener(view -> skip());

        new Handler().postDelayed(() -> {
            if (!isSkip && !isBack) {
                Intent intent = new Intent(SplashActivity.this, MainActivity.class);
                startActivity(intent);
                finish();
            }
        }, 5000);

    }


    @Override
    public void onBackPressed() {
        super.onBackPressed();
        isBack = true;
    }
}